subroutine symabcaab(iabc, ibca, icab, iout, popina, popinb, irrepabc)
use mod_iop 
use mod_t
implicit none
integer, intent(in) :: popina(8), popinb(8), irrepabc
real*8, intent(inout)::iabc(*), ibca(*), icab(*), iout(*)
if(prec==8.and.igpu==0) then 
  call symabcaab_d(iabc, ibca, icab, iout, popina, popinb, irrepabc)
elseif(prec==4.and.igpu==0) then 
  call symabcaab_s(iabc, ibca, icab, iout, popina, popinb, irrepabc)
elseif(prec==8.and.igpu==1) then 
  call symabcaab_dg(iabc, ibca, icab, iout, popina, popinb, irrepabc)
elseif(prec==4.and.igpu==1) then 
  call symabcaab_sg(iabc, ibca, icab, iout, popina, popinb, irrepabc)
endif
!
return
end
subroutine symabcaab_d(iabc, ibca, icab, iout, popina, popinb, irrepabc)
use mod_symm
use mod_orbit
use mod_t
implicit none
integer, intent(in) :: popina(8), popinb(8), irrepabc
real*8, intent(inout)::iabc(*), ibca(*), icab(*), iout(*)
integer, external :: irpdso, isymoffso, idsymabc, isymoffabc
integer irrepa, irrepb, irrepc, irrepab, irrepbc, irrepca
integer idxabc, idxbc, idxcab, idxout, npop2(8), npop22(8)
integer ioffabc, ioffbca, ioffcab, ioffout, idxtest
integer irrep, numa, numb, numc, a, b, c, idxbca
integer numab, numbc, numca
integer irrepac, irrepcb, numcb, numac, ioffacb, ioffcba
integer idxacb, idxcba
! a<b,c = abc + bca -acb + cab - cba
do irrep = 1, nirrep 
   npop2(irrep) = irpdso(irrep, popina, popina, 0)
   npop22(irrep) = irpdso(irrep, popina, popinb, 1) 
enddo 
!
idxtest =0
do irrepc = 1, nirrep 
   irrepab = dirprd(irrepc, irrepabc) 
   numab = irpdso(irrepab, popina, popina, 0)
   do irrepb = 1, nirrep 
      irrepa = dirprd(irrepb, irrepab)
      irrepbc = dirprd(irrepb, irrepc) 
      irrepca = dirprd(irrepc, irrepa)
      irrepac = irrepca
      irrepcb = irrepbc
      numbc = irpdso(irrepbc, popina, popinb, 1)
      numca = irpdso(irrepca, popina, popinb, 1)
      numcb = numbc 
      numac = numca
      numa = popina(irrepa)
      numb = popina(irrepb)
      numc = popinb(irrepc) 
! a<b,c = abc + bca -acb + cab - cba
      ioffabc = isymoffso(irrepc, irrepabc, npop2, popinb, 1) - 1 &
              + isymoffso(irrepb, irrepab, popina, popina, 0) - 1  
      ioffbca = isymoffso(irrepa, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepbc, popina, popinb, 1) - 1  
      ioffacb = isymoffso(irrepb, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepac, popina, popinb, 1) - 1  
      ioffcab = isymoffso(irrepb, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepa, irrepca, popinb, popina, 1) - 1
      ioffcba = isymoffso(irrepa, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepb, irrepcb, popinb, popina, 1) - 1
      if(irrepa>irrepb) cycle
      if(irrepa==irrepb) then 
!$omp parallel do
          do c = 1, numc 
          do b = 2, numb 
          do a = 1, b-1 
             idxabc = ioffabc + (c-1)*numab + (b-1)*(b-2)/2 + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
             idxcab = ioffcab + (b-1)*numca + (a-1)*numc + c
             idxcba = ioffcba + (a-1)*numcb + (b-1)*numc + c
!             write(6,'(A, I4, I4, I4, I4, I4)')'idxabc', idxabc, a, b, c, ioffabc
             iout(idxabc) = iabc(idxabc) + ibca(idxbca) - ibca(idxacb) & 
                          - icab(idxcab) + icab(idxcba)
          enddo
          enddo
          enddo 
!$omp end parallel do
!          write(6,'(A,i4,i4,i4,i4)')'idxtest', idxtest, irrepa, irrepb, irrepc
      elseif(irrepa<irrepb) then 
!$omp parallel do
          do c = 1, numc 
          do b = 1, numb 
          do a = 1, numa 
             idxabc = ioffabc + (c-1)*numab + (b-1)*numa + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
             idxcab = ioffcab + (b-1)*numca + (a-1)*numc + c
             idxcba = ioffcba + (a-1)*numcb + (b-1)*numc + c
             iout(idxabc) = iabc(idxabc) + ibca(idxbca) - ibca(idxacb) & 
                          - icab(idxcab) + icab(idxcba)
          enddo
          enddo
          enddo 
!$omp end parallel do
       endif
    enddo
enddo
!write(6,*)'idxtest', idxtest
return
end
subroutine symabcaab_s(iabc, ibca, icab, iout, popina, popinb, irrepabc)
use mod_symm
use mod_orbit
use mod_t
implicit none
integer, intent(in) :: popina(8), popinb(8), irrepabc
real*4, intent(inout)::iabc(*), ibca(*), icab(*), iout(*)
integer, external :: irpdso, isymoffso, idsymabc, isymoffabc
integer irrepa, irrepb, irrepc, irrepab, irrepbc, irrepca
integer idxabc, idxbc, idxcab, idxout, npop2(8), npop22(8)
integer ioffabc, ioffbca, ioffcab, ioffout, idxtest
integer irrep, numa, numb, numc, a, b, c, idxbca
integer numab, numbc, numca
integer irrepac, irrepcb, numcb, numac, ioffacb, ioffcba
integer idxacb, idxcba
! a<b,c = abc + bca -acb + cab - cba
do irrep = 1, nirrep 
   npop2(irrep) = irpdso(irrep, popina, popina, 0)
   npop22(irrep) = irpdso(irrep, popina, popinb, 1) 
enddo 
!
idxtest =0
do irrepc = 1, nirrep 
   irrepab = dirprd(irrepc, irrepabc) 
   numab = irpdso(irrepab, popina, popina, 0)
   do irrepb = 1, nirrep 
      irrepa = dirprd(irrepb, irrepab)
      irrepbc = dirprd(irrepb, irrepc) 
      irrepca = dirprd(irrepc, irrepa)
      irrepac = irrepca
      irrepcb = irrepbc
      numbc = irpdso(irrepbc, popina, popinb, 1)
      numca = irpdso(irrepca, popina, popinb, 1)
      numcb = numbc 
      numac = numca
      numa = popina(irrepa)
      numb = popina(irrepb)
      numc = popinb(irrepc) 
! a<b,c = abc + bca -acb + cab - cba
      ioffabc = isymoffso(irrepc, irrepabc, npop2, popinb, 1) - 1 &
              + isymoffso(irrepb, irrepab, popina, popina, 0) - 1  
      ioffbca = isymoffso(irrepa, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepbc, popina, popinb, 1) - 1  
      ioffacb = isymoffso(irrepb, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepac, popina, popinb, 1) - 1  
      ioffcab = isymoffso(irrepb, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepa, irrepca, popinb, popina, 1) - 1
      ioffcba = isymoffso(irrepa, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepb, irrepcb, popinb, popina, 1) - 1
      if(irrepa>irrepb) cycle
      if(irrepa==irrepb) then 
!$omp parallel do
          do c = 1, numc 
          do b = 2, numb 
          do a = 1, b-1 
             idxabc = ioffabc + (c-1)*numab + (b-1)*(b-2)/2 + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
             idxcab = ioffcab + (b-1)*numca + (a-1)*numc + c
             idxcba = ioffcba + (a-1)*numcb + (b-1)*numc + c
!             write(6,'(A, I4, I4, I4, I4, I4)')'idxabc', idxabc, a, b, c, ioffabc
             iout(idxabc) = iabc(idxabc) + ibca(idxbca) - ibca(idxacb) & 
                          - icab(idxcab) + icab(idxcba)
          enddo
          enddo
          enddo 
!$omp end parallel do
!          write(6,'(A,i4,i4,i4,i4)')'idxtest', idxtest, irrepa, irrepb, irrepc
      elseif(irrepa<irrepb) then 
!$omp parallel do
          do c = 1, numc 
          do b = 1, numb 
          do a = 1, numa 
             idxabc = ioffabc + (c-1)*numab + (b-1)*numa + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
             idxcab = ioffcab + (b-1)*numca + (a-1)*numc + c
             idxcba = ioffcba + (a-1)*numcb + (b-1)*numc + c
             iout(idxabc) = iabc(idxabc) + ibca(idxbca) - ibca(idxacb) & 
                          - icab(idxcab) + icab(idxcba)
          enddo
          enddo
          enddo 
!$omp end parallel do
       endif
    enddo
enddo
!write(6,*)'idxtest', idxtest
return
end
subroutine symabcaab_dg(iabc, ibca, icab, iout, popina, popinb, irrepabc)
use mod_symm
use mod_orbit
use mod_t
implicit none
integer, intent(in) :: popina(8), popinb(8), irrepabc
real*8, intent(inout),device::iabc(*), ibca(*), icab(*), iout(*)
integer, external :: irpdso, isymoffso, idsymabc, isymoffabc
integer irrepa, irrepb, irrepc, irrepab, irrepbc, irrepca
integer idxabc, idxbc, idxcab, idxout, npop2(8), npop22(8)
integer ioffabc, ioffbca, ioffcab, ioffout, idxtest
integer irrep, numa, numb, numc, a, b, c, idxbca
integer numab, numbc, numca
integer irrepac, irrepcb, numcb, numac, ioffacb, ioffcba
integer idxacb, idxcba
! a<b,c = abc + bca -acb + cab - cba
do irrep = 1, nirrep 
   npop2(irrep) = irpdso(irrep, popina, popina, 0)
   npop22(irrep) = irpdso(irrep, popina, popinb, 1) 
enddo 
!
idxtest =0
do irrepc = 1, nirrep 
   irrepab = dirprd(irrepc, irrepabc) 
   numab = irpdso(irrepab, popina, popina, 0)
   do irrepb = 1, nirrep 
      irrepa = dirprd(irrepb, irrepab)
      irrepbc = dirprd(irrepb, irrepc) 
      irrepca = dirprd(irrepc, irrepa)
      irrepac = irrepca
      irrepcb = irrepbc
      numbc = irpdso(irrepbc, popina, popinb, 1)
      numca = irpdso(irrepca, popina, popinb, 1)
      numcb = numbc 
      numac = numca
      numa = popina(irrepa)
      numb = popina(irrepb)
      numc = popinb(irrepc) 
! a<b,c = abc + bca -acb + cab - cba
      ioffabc = isymoffso(irrepc, irrepabc, npop2, popinb, 1) - 1 &
              + isymoffso(irrepb, irrepab, popina, popina, 0) - 1  
      ioffbca = isymoffso(irrepa, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepbc, popina, popinb, 1) - 1  
      ioffacb = isymoffso(irrepb, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepac, popina, popinb, 1) - 1  
      ioffcab = isymoffso(irrepb, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepa, irrepca, popinb, popina, 1) - 1
      ioffcba = isymoffso(irrepa, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepb, irrepcb, popinb, popina, 1) - 1
      if(irrepa>irrepb) cycle
      if(irrepa==irrepb) then 
!$acc kernels 
!$acc loop independent
          do c = 1, numc 
!$acc loop independent
          do b = 2, numb 
!$acc loop independent
          do a = 1, b-1 
             idxabc = ioffabc + (c-1)*numab + (b-1)*(b-2)/2 + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
             idxcab = ioffcab + (b-1)*numca + (a-1)*numc + c
             idxcba = ioffcba + (a-1)*numcb + (b-1)*numc + c
!             write(6,'(A, I4, I4, I4, I4, I4)')'idxabc', idxabc, a, b, c, ioffabc
             iout(idxabc) = iabc(idxabc) + ibca(idxbca) - ibca(idxacb) & 
                          - icab(idxcab) + icab(idxcba)
          enddo
          enddo
          enddo 
!$acc end kernels
!          write(6,'(A,i4,i4,i4,i4)')'idxtest', idxtest, irrepa, irrepb, irrepc
      elseif(irrepa<irrepb) then 
!$acc kernels
!$acc loop independent
          do c = 1, numc 
!$acc loop independent
          do b = 1, numb 
!$acc loop independent
          do a = 1, numa 
             idxabc = ioffabc + (c-1)*numab + (b-1)*numa + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
             idxcab = ioffcab + (b-1)*numca + (a-1)*numc + c
             idxcba = ioffcba + (a-1)*numcb + (b-1)*numc + c
             iout(idxabc) = iabc(idxabc) + ibca(idxbca) - ibca(idxacb) & 
                          - icab(idxcab) + icab(idxcba)
          enddo
          enddo
          enddo 
!$acc end kernels
       endif
    enddo
enddo
!write(6,*)'idxtest', idxtest
return
end
subroutine symabcaab_sg(iabc, ibca, icab, iout, popina, popinb, irrepabc)
use mod_symm
use mod_orbit
use mod_t
implicit none
integer, intent(in) :: popina(8), popinb(8), irrepabc
real*4, intent(inout),device::iabc(*), ibca(*), icab(*), iout(*)
integer, external :: irpdso, isymoffso, idsymabc, isymoffabc
integer irrepa, irrepb, irrepc, irrepab, irrepbc, irrepca
integer idxabc, idxbc, idxcab, idxout, npop2(8), npop22(8)
integer ioffabc, ioffbca, ioffcab, ioffout, idxtest
integer irrep, numa, numb, numc, a, b, c, idxbca
integer numab, numbc, numca
integer irrepac, irrepcb, numcb, numac, ioffacb, ioffcba
integer idxacb, idxcba
! a<b,c = abc + bca -acb + cab - cba
do irrep = 1, nirrep 
   npop2(irrep) = irpdso(irrep, popina, popina, 0)
   npop22(irrep) = irpdso(irrep, popina, popinb, 1) 
enddo 
!
idxtest =0
do irrepc = 1, nirrep 
   irrepab = dirprd(irrepc, irrepabc) 
   numab = irpdso(irrepab, popina, popina, 0)
   do irrepb = 1, nirrep 
      irrepa = dirprd(irrepb, irrepab)
      irrepbc = dirprd(irrepb, irrepc) 
      irrepca = dirprd(irrepc, irrepa)
      irrepac = irrepca
      irrepcb = irrepbc
      numbc = irpdso(irrepbc, popina, popinb, 1)
      numca = irpdso(irrepca, popina, popinb, 1)
      numcb = numbc 
      numac = numca
      numa = popina(irrepa)
      numb = popina(irrepb)
      numc = popinb(irrepc) 
! a<b,c = abc + bca -acb + cab - cba
      ioffabc = isymoffso(irrepc, irrepabc, npop2, popinb, 1) - 1 &
              + isymoffso(irrepb, irrepab, popina, popina, 0) - 1  
      ioffbca = isymoffso(irrepa, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepbc, popina, popinb, 1) - 1  
      ioffacb = isymoffso(irrepb, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepac, popina, popinb, 1) - 1  
      ioffcab = isymoffso(irrepb, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepa, irrepca, popinb, popina, 1) - 1
      ioffcba = isymoffso(irrepa, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepb, irrepcb, popinb, popina, 1) - 1
      if(irrepa>irrepb) cycle
      if(irrepa==irrepb) then 
!$acc kernels 
!$acc loop independent
          do c = 1, numc 
!$acc loop independent
          do b = 2, numb 
!$acc loop independent
          do a = 1, b-1 
             idxabc = ioffabc + (c-1)*numab + (b-1)*(b-2)/2 + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
             idxcab = ioffcab + (b-1)*numca + (a-1)*numc + c
             idxcba = ioffcba + (a-1)*numcb + (b-1)*numc + c
!             write(6,'(A, I4, I4, I4, I4, I4)')'idxabc', idxabc, a, b, c, ioffabc
             iout(idxabc) = iabc(idxabc) + ibca(idxbca) - ibca(idxacb) & 
                          - icab(idxcab) + icab(idxcba)
          enddo
          enddo
          enddo 
!$acc end kernels
!          write(6,'(A,i4,i4,i4,i4)')'idxtest', idxtest, irrepa, irrepb, irrepc
      elseif(irrepa<irrepb) then 
!$acc kernels
!$acc loop independent
          do c = 1, numc 
!$acc loop independent
          do b = 1, numb 
!$acc loop independent
          do a = 1, numa 
             idxabc = ioffabc + (c-1)*numab + (b-1)*numa + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
             idxcab = ioffcab + (b-1)*numca + (a-1)*numc + c
             idxcba = ioffcba + (a-1)*numcb + (b-1)*numc + c
             iout(idxabc) = iabc(idxabc) + ibca(idxbca) - ibca(idxacb) & 
                          - icab(idxcab) + icab(idxcba)
          enddo
          enddo
          enddo 
!$acc end kernels
       endif
    enddo
enddo
!write(6,*)'idxtest', idxtest
return
end
